NAME=db
MAIN=Gen
JAVAC=javac -nowarn
JAVA=java
JAVADOC=javadoc
JAR=jar
MANIFEST=manifest.mf
PHPDOC=phpdoc

all: $(MAIN).class
run: $(MAIN).run
re: clean compile
rt: runtests

compile:
	$(JAVAC) -g *.java

%.class:%.java
	$(JAVAC) -g $<

%.run:%.class
	$(JAVA) $*

%.tar.gz:%.tar
	gzip -9 -f $^

$(NAME).tar: Makefile *.java *.sh build.xml ext  README
	tar cvf $@ $^

runtests: compile TestSuite.run

dist: $(NAME).tar.gz

api/java:
	mkdir -p $@

api/php:
	mkdir -p $@

docs: javadoc phpdoc

javadoc: make.run api/java 
	$(JAVADOC) -d api/java *.rb *.php *.py *.java *.pl -sourcetab 2 \
		-linksource -protected -use src/java/*.java \
		-link "http://java.sun.com/j2se/1.5.0/docs/api/"

phpdoc: make.run api/php
	$(PHPDOC) -s on -d src/php -t api/php

upload: dist jars docs
	ant upload-all

show:
	open http://jeffpalm.com/$(NAME)

make.run:
	. make.sh

test:
	chmod +x *.sh
	. testall.sh

jars: $(NAME)-java.jar $(NAME)-php.jar $(NAME)-rb.jar $(NAME)-py.jar $(NAME)-pl.jar

$(NAME)-java.jar: make.run manifest.mf
	$(JAR) cvfm $@ manifest.mf -C src/java .

$(NAME)-php.jar: make.run
	$(JAR) cvfm $@ manifest.mf -C src/php .

$(NAME)-rb.jar: make.run
	$(JAR) cvfm $@ manifest.mf -C src/rb .

$(NAME)-py.jar: make.run
	$(JAR) cvfm $@ manifest.mf -C src/py .

$(NAME)-pl.jar: make.run
	$(JAR) cvfm $@ manifest.mf -C src/pl .

manifest.mf:
	echo "Main-class: Test" > $@

allclean: clean distclean docclean genclean srcclean

distclean:
	rm -f $(NAME).tar $(NAME).tar.gz

genclean:
	rm -rf src

docclean:
	rm -rf api

srcclean:
	rm -f `find . -name "*~"` manifest.mf

clean:
	rm -f *.class